package com.sc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sc.mapper.TitleMapper;
import com.sc.mapper.TitletypeMapper;
import com.sc.pojo.Title;
import com.sc.service.TitleAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class TitleAdminServiceImpl implements TitleAdminService {
    @Autowired
    TitleMapper mapper;
    @Override
    public PageInfo<Title> titleAdmin(Integer pageNum, Integer pageSize,Integer id) {
        PageHelper.startPage(pageNum,pageSize);
        List<Title> titles = mapper.showTitle(id);
        return new PageInfo<>(titles);
    }

    @Override
    public Title checkTitle(String title) {

        return mapper.checkTitle(title);
    }

    @Override
    public int add(Title title) {
        return mapper.insertSelective(title);
    }

    @Override
    public int deleteAll(Integer[] ids) {
        return mapper.deleteAll(ids);
    }

    @Override
    public int updateAll(Integer[] ids) {
        return mapper.updateAll(ids);
    }

    @Override
    public int delete(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public Title editSelect(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int edit(Title title) {
        return mapper.updateByPrimaryKeySelective(title);
    }

    @Override
    public int updateOne(Integer id) {
        return mapper.updateOne(id);
    }

    @Override
    public int insertAll(List<Title> list) {
        return mapper.insertAll(list);
    }

    @Override
    public List<Title> levelExam(Integer typeId, String difficulty) {

        return mapper.levelExam(typeId,difficulty);
    }

    @Override
    public int addExamInfo(List<Title> titles, Long id) {
        for (Title t:titles) {
            mapper.insertExamInfo(id,t.getId());
        }
        return 0;
    }

    @Override
    public List<Title> addTitle(Integer num) {
        return mapper.addTitle(num);
    }

    @Override
    public List<Title> selectAllTitle(Integer[] ids) {
        return mapper.selectAllTitle(ids);
    }

    @Override
    public int deleteDetail(Integer id) {

        return mapper.deleteDetail(id);
    }

    @Override
    public int deleteExamDetail(Long id) {
        return mapper.deleteExamDetail(id);
    }

    @Override
    public List<Title> myExamTest(Long id) {

        return mapper.myExamTest(id);
    }

}
